﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Core.DependencyInjection;
using Core.NetWorkUtils;
using DomainModels.DomainModels.JsonModels;

namespace DounloderV2WinFormsUI.Forms
{
    public sealed partial class MainUserInfo : UserControl
    {
        private readonly IWebHelper _webHelper = NinjectFactory.Resolve<WebHelper>();

        public Users CurentUser;

        public MainUserInfo()
        {
            InitializeComponent();
            BackColor = Color.DarkGray;
        }

        public void SetUser(Users user)
        {
            CurentUser = user;
            lnclblUserName.Text = string.Format("{0} {1}", user.last_name, user.first_name);
            lnclblUserName.Click += LnclblUserNameOnClick;
            BackColor = DefaultBackColor;
            LoadImage();
        }

        private void LnclblUserNameOnClick(object sender, EventArgs eventArgs)
        {
            Process.Start(string.Format("https://vk.com/{0}", CurentUser.screen_name));
        }

        private void LoadImage()
        {
            var data = _webHelper.GetData(CurentUser.photo_big);
            using (var ms = new MemoryStream())
            {
                ms.Write(data, 0, Convert.ToInt32(data.Length));
                userPictureBox.Image = new Bitmap(ms, false);
            }
        }
    }
}
